package com.feihao.zhou.UDP.demo01;

import java.util.concurrent.*;

public class ThreadPoolExecutorTest {
    public static void main(String[] args) {
        // 参数一：核心线程数量
        // 参数二：最大线程数
        // 参数三：空闲线程最大存活时间
        // 参数四：时间单位
        // 参数五：任务队列
        // 参数六：创建线程工厂
        // 参数七：任务的拒绝策略

        ThreadPoolExecutor pool = new ThreadPoolExecutor(3, 5, 2, TimeUnit.MINUTES,
                new ArrayBlockingQueue<>(8) , Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());

        System.out.println(pool.getPoolSize());
        pool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("线程任务执行");
            }
        });


        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });
        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });
        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });
        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });
        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });
        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });
        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });
        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });
        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });
        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });


        System.out.println("存活的" + pool.getActiveCount());
        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });
        pool.submit(() -> {
            System.out.println("再次执行线程任务");
        });

        System.out.println(pool.getPoolSize());

        pool.shutdown();

    }
}
